home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / misc_pto / 899 / cpro1.c < prev    next >
C/C++ Source or Header  |  1990-07-22  |  4KB  |  135 lines

  1. /* TurboC v1.5 & v2.0 Source File */
  2. /*     File : CPRO-1.C
  3.        Date : March 25, 1990  -- create date
  4.                               -- Finish Date
  5.        Author: Jovo J. Filipovich
  6.        Purpose :  Routines used by Turbo Prolog V2.0,
  7.                   these are to speed up common routines
  8.                   which are much more efficient than the
  9.                   declaritive brothers in TP.
  10.  
  11. */
  12.  
  13. #include <prolog.h>
  14. #include <prolist.h>
  15. #include <string.h>
  16.  
  17. void maxgslistlen_0(StrList *InList, unsigned int *MaxLength);
  18. void memgslist_0(char *gs, StrList *gsList);
  19. void invattr_0(unsigned int InAttr, unsigned int *InvAttr);
  20. void gslistlen_0(StrList *gsList, unsigned int *ElemCount);
  21. void upchar_0(char Inchar, char *Upchar);
  22. void expgslist_0(char *TargetDelete,StrList *InList,StrList **NewList);
  23.  
  24.  
  25.  
  26. void maxgslistlen_0(StrList *InList, unsigned int *MaxLength)
  27. /*
  28.    Deterministic -- Returns the longest string length for the
  29.                     given lis of strings.
  30. */
  31. {
  32.   unsigned int Temp,Max = 0;
  33.   StrList *Current;
  34.  
  35.   Current = InList;                        /* Init Pointers */
  36.   while ((Current->NodeType) != is_null)
  37.     {
  38.       Temp = _strlen((Current->Str));
  39.       Max = (Temp > Max) ? Temp : Max;
  40.       Current = Current->Next;
  41.     }
  42.   *MaxLength = Max;
  43. };
  44.  
  45.  
  46. void memgslist_0(char *gs, StrList *gsList)
  47. /*
  48.    NonDeterministic -- Verifies the membership of a string in
  49.                        a list of strings.  If that string is found in
  50.                        the list, this predicate succeeds, if not
  51.                        then this predicate FAILS.
  52. */
  53. {
  54.   int Found = -1;
  55.   StrList *Current;
  56.  
  57.   Current = gsList;
  58.   while (((Current->NodeType) != is_null) && (Found == -1))
  59.     {
  60.       Found = (_strcmp((Current->Str),gs) == 0) ? 0 : -1;
  61.       Current = Current->Next;
  62.     };
  63.   if (Found == -1)
  64.     {
  65.       fail_cc();
  66.     };
  67. };
  68.  
  69. void invattr_0(unsigned int InAttr, unsigned int *InvAttr)
  70. {
  71.   *InvAttr = (InAttr & 0x08)|((InAttr & 0x07) << 4)|((InAttr & 0x70) >> 4);
  72. };
  73.  
  74. void gslistlen_0(StrList *gsList, unsigned int *ElemCount)
  75. {
  76.   StrList *Current;
  77.   unsigned int tcount = 0;
  78.  
  79.   Current = gsList;
  80.   while ((Current->NodeType) != is_null)
  81.     {
  82.       tcount++;
  83.       Current = Current->Next;
  84.     };
  85.   *ElemCount = tcount;
  86. };
  87.  
  88.  
  89. void upchar_0(char Inchar, char *Upchar)
  90. {
  91.   *Upchar = ((Inchar >= 'a') && (Inchar <= 'z')) ? Inchar - 0x20 : Inchar;
  92. };
  93.  
  94. void expgslist_0(char *TargetDelete,StrList *InList,StrList **NewList)
  95. {
  96.   StrList *Current,*Prev,*Fore;
  97.   StrList *Nlst,*Anchor;
  98.   int Found = -1;
  99.  
  100.   Prev = 0x00;     /* Initialy */
  101.   Current = InList;
  102.   Fore = Current->Next;
  103.   Anchor = Nlst = alloc_gstack(sizeof(StrList));  /* Allocate first node */
  104.   while ((Current->NodeType != is_null) && (Found == -1))
  105.     {
  106.       Found = (_strcmp((Current->Str),TargetDelete) == 0) ? 0 : -1;
  107.       if (Prev != 0x00)
  108.         {
  109.           Nlst->NodeType = Prev->NodeType;
  110.           Nlst->Str = alloc_gstack(_strlen(Prev->Str)+1);
  111.           _strcpy(Nlst->Str,Prev->Str);
  112.           Nlst->Next = alloc_gstack(sizeof(StrList));  /* Make another new node */
  113.           Nlst = Nlst->Next;
  114.         };
  115.       Prev = Current;
  116.       Current = Fore;
  117.       Fore = Fore->Next;
  118.     };
  119.   /* Coming into here, the item has been found and PREV holds it's location,
  120.      thus, the item in prev will be 'skipped' rendering a deletion */
  121.   while (Current->NodeType != is_null)
  122.     {
  123.       Nlst->NodeType = Current->NodeType;
  124.       Nlst->Str = alloc_gstack(_strlen(Current->Str)+1);
  125.       _strcpy(Nlst->Str,Current->Str);
  126.       Nlst->Next = alloc_gstack(sizeof(StrList));  /* Make another new node */
  127.       Nlst = Nlst->Next;
  128.       Current = Current->Next;
  129.     };
  130.   Nlst->NodeType = is_null;  /* The last node has been made */
  131.   Nlst->Str = 0x00;
  132.   Nlst->Next = 0x00;
  133.   *NewList = Anchor;
  134. };
  135.